import AdSearch from '@/components/AdSearch';
import AdSelect from '@/components/AdSelect';
import { queryPerson } from '@/utils/common';

export const codes = {
  page: 'PAPERVERIFICATION',
  select: 'PAPERVERIFICATION_SELECT',
  add: 'PAPERVERIFICATION_ADD',
  // edit: 'DRIVERPAPERS_UPDATE',
  showDetail: 'PAPERVERIFICATION_VIEW',
  delete: 'PAPERVERIFICATION_DEL',
  commit: 'PAPERVERIFICATION_COMMIT',
  audit: 'PAPERVERIFICATION_AUDIT',
  discernPaper: 'PAPERVERIFICATION_PAPER_DISCERN',
  paperDetail: 'PAPERVERIFICATION_PAPER_VIEW',
  paperEdit: 'PAPERVERIFICATION_PAPER_EDIT',
  paperDel: 'PAPERVERIFICATION_PAPER_DEL',
};

export const formate = 'YYYY-MM-DD';
export const formateNOSecond = 'YYYY-MM-DD HH:mm';

// 类型：
export const ocrTypeList = [
  { code: 'COMPANY', value: '公司' },
  { code: 'VEHICLE', value: '车辆' }
]
//状态：
export const statusList = [
  { code: 'DRAFT', value: '草稿' },
  { code: 'AUDITING', value: '审核中' }, //审核中==已提交
  { code: 'FINISH', value: '完成' },
]
//审核
export const auditList = [
  { code: 'PASS', value: '通过' },
  { code: 'REFUSE', value: '拒绝' }
]
const uploadOnly = false;

export const allDispatchType = {
  list: 'paperVerify/selectOcrList',
  detail: 'paperVerify/ocrInfoDetail',
  save: 'paperVerify/saveDriverPaper',
  value: 'paperVerify/allValus',
  partsDetail: 'paperVerify/selectPapersDetail',
  setTabsName: 'common/setTabsName',
  queryDriverPaperDict: 'component/queryDriverPaperDict',
  auditOcr: 'paperVerify/auditOcr',
  delOcr: 'paperVerify/deleteOcr',
  commitOcr: 'paperVerify/commitOcr',
  //ocr证件
  ocrPapersList: 'paperVerify/ocrPapersList',
  ocrPapersInfo: 'paperVerify/ocrPapersInfo',
  discern: 'paperVerify/discernOcrPapers',
  savePaper: 'paperVerify/saveOcrPapers',
  delOcrPapers: 'paperVerify/delOcrPapers'
};
export const routeUrl = {
  detail: '/supplierManage/paperVerifyList/paperVerifyDetail',
  add: '/supplierManage/paperVerifyList/paperVerifyAdd',
  edit: '/supplierManage/paperVerifyList/paperVerifyEdit',
  list: '/supplierManage/paperVerifyList',
};

export const allUrl = {
  userList: 'tms/tms-papers/selectUserList_s',
  companyList: 'mds/d-customer/selectCompany',
  driverList: 'tms/tms-papers/selectDriverList_s',
  driverDetail: 'tms/tms-driver/viewDetails',
};

export function saveAllValues({ payload = {}, props } = {}) {
  const { dispatch } = props;
  dispatch({
    type: allDispatchType.value,
    payload,
  });
}

export function selectOcrList({ payload = {}, props } = {}) {
  const { dispatch, searchValue } = props;
  dispatch({
    type: allDispatchType.list,
    payload,
    callback: data => {
      if (!data) return;
      queryPerson({ data, props, url: allUrl.userList });
    },
  });
}

export function selectDetail({ type, payload, props, callback }) {
  const { dispatch } = props;
  dispatch({
    type,
    payload,
    callback: data => {
      if (!data) return;
      callback && callback(data);
    },
  });
}

export function renderTableAdSelect({ key, data, value, props }) {
  let params = { onlyRead: true, value };
  if (key) {
    const { dictObject } = props;
    params = { data: dictObject[key], payload: { code: [key] }, ...params };
  } else {
    params = { data, ...params };
  }
  return <AdSelect {...params} />;
}

export function renderTableAdSearch({ value, props }) {
  const { searchValue } = props;
  if (!value || !searchValue) return '';
  const params = {
    onlyRead: true,
    value: searchValue[value],
    label: 'loginName',
    name: 'sysName',
  };
  return <AdSearch {...params} />;
}

//公司证件:
export const ocrCompanyList = [
  { code: "BUSINESS_LICENSE", value: "营业执照", counted: "0", uploadOnly },
  { code: "TRANSPORT_OPERATING_LICENSE", value: "道路运输证", counted: "0", uploadOnly: "true" },
  { code: "CARGO_POLICY", value: "公司货运保险单", counted: "0", uploadOnly: "true" },
  { code: "OPEN_ACCOUNT_LICENSE", value: "开户许可证", counted: "0", uploadOnly: "true" },
  { code: "CLEAN_PLEDGE", value: "廉洁承诺书", counted: "0", uploadOnly: "true" },
  { code: "CONTRACT", value: "合同", counted: "0", uploadOnly: "true" },
  { code: "OTHER", value: "其它", counted: "0", uploadOnly: "true" },
]
//车辆&司机证件:
export const ocrVDList = [
  { code: "VEHICLE_LICENSE", value: "行驶证", counted: "0", uploadOnly },
  { code: "TRANSPORTATION_LICENSE", value: "道路运输证", counted: "0", uploadOnly },
  { code: "ID_CARD", value: "身份证", counted: "0", uploadOnly },
  { code: "DRIVER_LICENSE", value: "驾驶证", counted: "0", uploadOnly },
]
//需要正、反面上传的附件
export const doubleArr = ['ID_CARD', 'DRIVER_LICENSE', 'VEHICLE_LICENSE'];
//只上传附件的：
export const onlyUploadPaper = ['TRANSPORT_OPERATING_LICENSE', 'CARGO_POLICY', 'OPEN_ACCOUNT_LICENSE', 'CLEAN_PLEDGE', 'CONTRACT', 'OTHER'];

//字段
export const fieldsForm = {
  //营业执照
  'BUSINESS_LICENSE': [
    { key: 'registrationNumber', value: '注册号/社会保障号', width: '140px' },
    { key: 'name', value: '企业名称' },
    { key: 'type', value: '公司/企业/主体类型', width: '150px' },
    { key: 'address', value: '住所/营业场所/企业住所', width: '200px' },
    { key: 'legalRepresentative', value: '法定代表人/负责人', width: '150px' },
    { key: 'registeredCapital', value: '注册资本' },
    { key: 'foundDate', value: '成立日期' },
    { key: 'businessTerm', value: '营业期限' },
    { key: 'businessScope', value: '经营范围' },
    { key: 'issueDate', value: '发照日期' },
    // { key: 'files', value: '正面图片', mode: 'upload' },
  ],
  //道路运输证
  'TRANSPORTATION_LICENSE': [
    { key: 'ownerName', value: '业户名称' },
    { key: 'licenseNumber', value: '道路运输证号', width: '130px' },
    { key: 'vehicleNumber', value: '车牌号牌' },
    { key: 'vehicleTyp', value: '车辆类型' },
    { key: 'maximumCapacity', value: '吨(座)位' },
    { key: 'vehicleSize', value: '车辆尺寸' },
    { key: 'issuingAuthority', value: '核发机关' },
    { key: 'issueDate', value: '签发日期' },
    { key: 'ownerAddress', value: '业户地址' },
    { key: 'economicType', value: '经济类型' },
    { key: 'businessCertificate', value: '经营许可证号', width: '130px' },
    { key: 'businessScope', value: '道路普通货物运输', width: '140px' },
    // { key: 'files', value: '图片', mode: 'upload' },
  ],
  //身份证
  'ID_CARD': [
    { key: 'name', value: '姓名' },
    { key: 'sex', value: '性别' },
    { key: 'birth', value: '出生日期' },
    { key: 'ethnicity', value: '民族' },
    { key: 'address', value: '地址' },
    { key: 'number', value: '身份证号' },
    { key: 'issue', value: '发证机关' },
    { key: 'validFrom', value: '有效起始日期', width: "130px" },
    { key: 'validTo', value: '有效结束日期', width: "130px" },
    // { key: 'files', value: '图片', mode: 'upload' },
  ],
  //驾驶证
  'DRIVER_LICENSE': [
    { key: 'number', value: '驾驶证号' },
    { key: 'name', value: '姓名' },
    { key: 'sex', value: '性别', mode: 'picker', selectList: ['男', '女'] },
    { key: 'nationality', value: '国籍' },
    { key: 'address', value: '住址' },
    { key: 'birth', value: '出生日期' },
    { key: 'issueDate', value: '初次领证日期', width: '130px' },
    { key: 'type', value: '准驾类型' },
    { key: 'validFrom', value: '有效起始日期', width: '130px' },
    { key: 'validTo', value: '有效结束日期', width: '130px' },
    { key: 'fileNo', value: '档案编码' },
    { key: 'record', value: '记录' },
    // { key: 'files', value: '图片', mode: 'upload' },
  ],
  //行驶证
  'VEHICLE_LICENSE': [
    { key: 'number', value: '号牌号码' },
    { key: 'vehicleType', value: '车辆类型' },
    { key: 'name', value: '所有人' },
    { key: 'address', value: '住址' },
    { key: 'useCharacter', value: '使用性质' },
    { key: 'model', value: '品牌型号' },
    { key: 'engineNo', value: '发动机号码', width: '130px' },
    { key: 'vin', value: '车辆识别代号', width: '130px' },
    { key: 'registerDate', value: '注册日期' },
    { key: 'issueDate', value: '发证日期' },
    { key: 'fileNo', value: '档案编码' },
    { key: 'approvedPassengers', value: '核定载人数', width: '130px' },
    { key: 'grossMass', value: '总质量' },
    { key: 'unladenMass', value: '整备质量' },
    { key: 'approvedLoad', value: '核定载质量', width: '130px' },
    { key: 'dimension', value: '外廓尺寸' },
    { key: 'tractionMass', value: '准牵引总质量', width: '130px' },
    { key: 'remarks', value: '备注' },
    { key: 'inspectionRecord', value: '检验记录' },
    { key: 'codeNumber', value: '条码号' },
    // { key: 'files', value: '图片', mode: 'upload' },
  ],
}